const gulp = require('gulp')
const cssmin = require('gulp-cssmin')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel')
const htmlmin = require('gulp-htmlmin')






const cssHandler = () => {
    return gulp
        .src('./src/css/*.css')
        .pipe(cssmin())
        .pipe(gulp.dest('./dist/css/'))
}

const jsHandler = () => {
    return gulp
        .src('./src/js/*.js')
        .pipe(babel({presets:['@babel/preset-env']}))
        .pipe(uglify())
        .pipe(gulp.dest('./dist/js/'))
}

const htmlHandler = () => {
    return gulp
        .src('./src/html/*.html')
        .pipe(htmlmin({
            collapseWhitespace:true,
            collapseBooleanAttributes:true,
            removeAttributeQuotes:true,
            removeComments:true,
            removeEmptyAttributes:true,
            removeScriptTypeAttributes:true,
            removeStyleLinkTypeAttributes:true,
            minifyCSS:true,
            minifyJS:true,
        }))
        .pipe(gulp.dest('./dist/html/'))
}

const imgHandler = () => {
    return gulp
        .src('./src/img/**.*')
        .pipe(gulp.dest('./dist/img/'))
}

const defaultHandler = gulp.parallel(cssHandler, jsHandler, htmlHandler, imgHandler)







const watchHandler = () => {
    gulp.watch('./src/css/*.css', cssHandler)
    gulp.watch('./src/js/*.js', jsHandler)
    gulp.watch('./src/html/*.html', htmlHandler)
    gulp.watch('./src/img/**.*', imgHandler)
}








module.exports = {
    cssHandler,
    jsHandler,
    htmlHandler,
    imgHandler,
    default: defaultHandler
}
